<?php namespace Admin\Controller;


use Admin\Model\ShopType;

class ShopTypeController extends AuthController{
	protected $db;
	//构造函数
	public function __init()
	{
		$this->db = new ShopType;
	}

    //动作
	public function index(){
		$data = $this->db->getAll();
		View::with('data',$data);
		View::make();
	}

	public function add()
	{
		if (IS_POST)
		{
			if ($this->db->store()) {
				View::success('添加成功','index');
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			View::make();
		}
	}

	public function edit()
	{
		if (IS_POST) {
			if ($this->db->edit()) {

				View::success('编辑修改成功','index');
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$field = $this->db->one($_GET['id']);
			View::with('field',$field);
			View::make();
		}
	}
}
